package com.ict.web.dto;

import com.ict.common.annotation.Excel;
import com.ict.common.utils.StringUtils;
import com.ict.common.utils.bean.BeanUtils;
import com.ict.common.utils.uuid.IdUtils;
import com.ict.web.controller.file.domain.YzqFile;
import com.ict.web.controller.file.dto.YzqFileDTO;
import com.ict.web.domain.Finance;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Data
public class FinanceAddDto {
    @ApiModelProperty(value = "项目id")
    private String proId;

    /**
     区发改委审批附件 */
    @Excel(name = "区发改委审批附件")
    @ApiModelProperty(value = "区发改委审批附件")
    private YzqFileDTO approvalAnnex;

    /** 区财政局审批附件 */
    @Excel(name = "区财政局审批附件")
    @ApiModelProperty(value = "区财政局审批附件")
    private YzqFileDTO approvalFinance;

    /**
     * 将 FinanceAddDto 转化为 YzqFile
     *
     * @param dto 接收dto
     * @return Finance
     */
    public static List<YzqFile> of(Finance bean,FinanceAddDto dto){
        List<YzqFile> fileList = new ArrayList<>();
        YzqFileDTO annexDto = dto.getApprovalAnnex();
        YzqFileDTO financeDto = dto.getApprovalFinance();

        if(StringUtils.isNotNull(dto.getApprovalAnnex())){
            YzqFile annex = new YzqFile();
            annex.setId(String.valueOf(IdUtils.snowId()));
            BeanUtils.copyProperties(annexDto,annex);
            fileList.add(annex);
            bean.setApprovalAnnexId(annex.getId());
        }

        if(StringUtils.isNotNull(dto.getApprovalFinance())){
            YzqFile finance = new YzqFile();
            finance.setId(String.valueOf(IdUtils.snowId()));
            BeanUtils.copyProperties(financeDto,finance);
            fileList.add(finance);
            bean.setApprovalFinanceId(finance.getId());
        }




        //设置ID
        bean.setFinanceId(IdUtils.snowId());
        //设置创建时间
        bean.setCreateTime(LocalDateTime.now());
        //设置创建时间
        bean.setUpdateTime(LocalDateTime.now());
        //设置物理删除标记
        bean.setDelFlag("0");

        return fileList;
    }
}
